package action.AC01;

import java.util.*;

import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.*;
import com.syslog.SysLogServices;
import com.util.Component;
import com.util.Util;
import services.AC01.AC01Services;
/**
* PersonMgrFacade:个人基础信息管理action
* @author fcl
* @version Wed Dec 23 16:16:39 CST 2015 bjh
* @since 1.0
*/ 
@Controller
@RequestMapping("AC01.do")
public class AC01Action {
	PublicSystem sys = PublicSystem.getInstance();
    AC01Services ss = new AC01Services();
    SysLogServices log = SysLogServices.getInstance();
	/**
	* 查询个人基础信息
	* @author bjh
	* @param request
	* @param response
	* @throws Exception
	*/ 
	@RequestMapping(params ="method=getAC01")
	public void getAc01(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	String AAC001 = Component.getQuest("aac001", request);
    	String AAC002 = Component.getQuest("aac002", request);
    	String AAC003 = Component.getQuest("aac003", request);
    	HashMap parms = sys.getGridSort(request);
    	String json = Util.Encode(ss.getAc01(new Object[] {AAC001,AAC002,AAC003},parms));
	    HashMap obj = new HashMap();
	    obj.put("domainid", "ZYK");  //分系统号，见sys_log_bm
	    obj.put("log_type", "T05");   //日志类别，见sys_log_bm
	    obj.put("userid", Component.getSession("userid", request)); //操作人
	    obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
	    obj.put("content", "人员基础信息查询，社会保障卡号为:"+AAC001+" ,证件号码："+AAC002+" ,姓名："+AAC003);  //日志内容，自己组合拼装
	    obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
	    obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm 
	    obj.put("datain", AAC003+","+AAC002+","+AAC003); //输入参数
	    obj.put("dataout", "Ok");//输出参数
	    log.sysLogMap(obj, request);
	    Component.print(json, response);
	}
	/**
	* 查询个人基础日志信息
	* @author bjh
	* @param request
	* @param response
	* @throws Exception
	*/ 
	@RequestMapping(params ="method=getTAC01")
	public void getTAc01(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	String log_type = Component.getQuest("log_type", request);
    	String userid = Component.getQuest("userid", request);
    	String czqd = Component.getQuest("czqd", request);
    	String czrlb = Component.getQuest("czrlb", request);
    	HashMap parms = sys.getGridSort(request);
    	String json = Util.Encode(ss.getTAc01(new Object[] {log_type,userid,czqd,czrlb},parms));
	    HashMap obj = new HashMap();
	    obj.put("domainid", "ZYK");  //分系统号，见sys_log_bm
	    obj.put("log_type", "T05");   //日志类别，见sys_log_bm
	    obj.put("userid", Component.getSession("userid", request)); //操作人
	    obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
	    obj.put("content", "人员基础日志信息查询，日志类型:"+log_type);  //日志内容，自己组合拼装
	    obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
	    obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm 
	    obj.put("datain", log_type); //输入参数
	    obj.put("dataout", "Ok");//输出参数
	    log.sysLogMap(obj, request);
	    Component.print(json, response);
	}
	/**
	* 查询个人基础日志信息
	* @author bjh
	* @param request
	* @param response
	* @throws Exception
	*/ 
	@RequestMapping(params ="method=getltAC01")
	public void getltAc01(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	List user= ss.getltAc01(Component.getQuest("lx", request));
	    Component.print(Util.Encode(user), response);
	}
	/**
	* 查询个人基础信息变更
	* @author bjh
	* @param request
	* @param response
	* @throws Exception
	*/ 
	@RequestMapping(params = "method=getAC01bg")
	public void getAC01bg(HttpServletRequest request, HttpServletResponse response) throws Exception {
	    String AAC001 = Component.getQuest("aac001", request);
    	String AAC002 = Component.getQuest("aac002", request);   	
    	String AAC003 = Component.getQuest("aac003", request);      	
    	HashMap parms = sys.getGridSort(request);
    	String json = Util.Encode(ss.getAc01bg(new Object[] {AAC001,AAC002,AAC003},parms));
    	HashMap obj=new HashMap();
	    obj.put("domainid", "ZYK");  //分系统号，见sys_log_bm
	    obj.put("log_type", "T05");   //日志类别，见sys_log_bm
	    obj.put("userid", Component.getSession("userid", request)); //操作人
	    obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
	    obj.put("content", "人员基础信息变更查询，社会保障卡号为:"+AAC001+" ,证件号码："+AAC002+" ,姓名："+AAC003);  //日志内容，自己组合拼装
	    obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
	    obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm
	    obj.put("datain", AAC003+","+AAC002+","+AAC003); //输入参数
	    obj.put("dataout", "Ok");//输出参数
	    log.sysLogMap(obj, request);
    	Component.print(json, response);
	}
	/**
	 * 获取选中数据的个人基础信息
	 * @author bjh
	 * @param request
	 * @param response
	 *@throws Exception
	 */
	@RequestMapping(params = "method=getAC01data")
	public void getAC01Data(HttpServletRequest request, HttpServletResponse response) throws Exception {
	    HashMap user = ss.getAC01Data(Component.getQuest("id", request));
	    Component.print(Util.Encode(user), response);
	} 
	/**
	 * 新增和更新个人基础信息
	 * @author bjh 
	 * @param request
	 * @param response
	 *@throws Exception
	 */
	@RequestMapping(params = "method=saveAC01")
	public void saveAC01(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String json = request.getParameter("data");
		String idreturn = "";	
		ArrayList rows = (ArrayList)Util.Decode(json);
		HashMap row = (HashMap)rows.get(0);
		String aae011 = Component.getSession("userid", request);
		row.put("aae011", aae011);
		
		String id = row.get("aac001") != null ? row.get("aac001").toString() : "";
		// 页面上如果主键为空的话为新增
		if(id.equals("")) {
			idreturn = ss.insertAC01( row);	
			String[] aa = idreturn.split(":");
			if(aa.length > 1  && !idreturn.contains("ORA-")){
				HashMap obj = new HashMap();
		  		obj.put("domainid", "ZYK");  //分系统号，见sys_log_bm
		  		obj.put("log_type", "T02");   //日志类别，见sys_log_bm
		  		obj.put("userid", aae011); //操作人
		  		obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
		  		obj.put("content", "人员基础信息新增，社会保障卡号为:"+aa[1]);  //日志内容，自己组合拼装
		  		obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
		  		obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm
		  		String strs2=row.get("aac003")+","+row.get("aac058")+","+row.get("aac002")+","+row.get("aacc01")+","+row.get("aac006")+","+row.get("aac004")+","+row.get("aac005")+","+row.get("aac161")+","+row.get("aae005");
		  		obj.put("datain", strs2); //输入参数
		  		obj.put("dataout", "Ok");//输出参数
		  		log.sysLogMap(obj, request);
			}
		}else {
			String[] aas=row.get("aac006").toString().split("T");
			String[] aas2=row.get("aacc01").toString().split("T");
			row.put("aac006", aas[0]);
			row.put("aacc01", aas2[0]);
			HashMap map = ss.getAc01Datas((String)row.get("aac001"));
			Iterator<Entry<String, String>> iter1 = map.entrySet().iterator();
			String str4 = "";
			//比较两个map中key相同value不同
		    while(iter1.hasNext()){
		    	Map.Entry<String, String> entry1 = (Entry<String, String>) iter1.next();
		        String mapvalue = entry1.getValue() == null?"":entry1.getValue();
		        String rowvalue = row.get(entry1.getKey())==null?"":(String)row.get(entry1.getKey());       
		        if (!mapvalue.equals(rowvalue)) {//若两个map中相同key对应的value不相等
		            HashMap row1=new HashMap();
		            String str3 = " 个人基础信息变更，修改字段为："+entry1.getKey()+" 变更前："+mapvalue+" 变更后："+rowvalue;
		            str4+=str3;
		        }
		    }
		    row.put("aae011", aae011);
			idreturn = ss.modifiedAC01(row);
			if("修改成功".equals(idreturn)){
				HashMap obj = new HashMap();
		  		obj.put("domainid", "ZYK");		//分系统号，见sys_log_bm
		  		obj.put("log_type", "T03");		//日志类别，见sys_log_bm
		  		obj.put("userid", aae011);	 //操作人
		  		obj.put("rwh", Component.getSession("rwid", request));		//任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
		  		obj.put("content", str4);  	//日志内容，自己组合拼装
		  		obj.put("czqd", "Q1");		//操作渠道，见sys_log_bm
		  		obj.put("czrlb", "L01"); 	//操作人类别，见sys_log_bm
		  		String strs2=row.get("aac003")+","+row.get("aac058")+","+row.get("aac002")+","+row.get("aacc01")+","+row.get("aac006")
		  		    			 +","+row.get("aac004")+","+row.get("aac005")+","+row.get("aac161")+","+row.get("aae005");
		  		obj.put("datain", strs2); //输入参数
		  		obj.put("dataout", "updateOk");//输出参数
		  		log.sysLogMap(obj, request);
			}
		}
		Component.print(idreturn, response);
	} 
	/**
	 * 新增特殊人员基础信息
	 * @author bjh 
	 * @param request
	 * @param response
	 *@throws Exception
	 */
	@RequestMapping(params = "method=savetsadd")
	public void savetsadd(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String json = request.getParameter("data");
		String idreturn = "";	
		ArrayList rows = (ArrayList)Util.Decode(json);
		HashMap row = (HashMap)rows.get(0);
		String aae011 = Component.getSession("userid", request);
		row.put("aae011", aae011);
		idreturn = ss.inserttsadd( row);	
		String[] aa = idreturn.split(":"); 
		if(aa[0].contains("保存成功")){ 
		HashMap obj = new HashMap();
	  	obj.put("domainid", "ZYK");  //分系统号，见sys_log_bm
	  	obj.put("log_type", "T02");   //日志类别，见sys_log_bm
	  	obj.put("userid", aae011); //操作人
	  	obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
	  	obj.put("content", "特殊人员基础信息新增，社会保障卡号为:"+aa[1]);  //日志内容，自己组合拼装
	  	obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
	  	obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm
	  	String strs2=row.get("aac003")+","+row.get("aac058")+","+row.get("aac002")+","+row.get("aacc01")+","+row.get("aac006")+","+row.get("aac004")+","+row.get("aac005")+","+row.get("aac161")+","+row.get("aae005");
	  	obj.put("datain", strs2); //输入参数
	  	obj.put("dataout", "Ok");//输出参数
	  	log.sysLogMap(obj, request);
		}else{
			HashMap obj = new HashMap();
		  	obj.put("domainid", "ZYK");  //分系统号，见sys_log_bm
		  	obj.put("log_type", "T02");   //日志类别，见sys_log_bm
		  	obj.put("userid", aae011); //操作人
		  	obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
		  	obj.put("content", "特殊人员基础信息新增失败:"+aa[0]);  //日志内容，自己组合拼装
		  	obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
		  	obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm
		  	String strs2=row.get("aac003")+","+row.get("aac058")+","+row.get("aac002")+","+row.get("aacc01")+","+row.get("aac006")+","+row.get("aac004")+","+row.get("aac005")+","+row.get("aac161")+","+row.get("aae005");
		  	obj.put("datain", strs2); //输入参数
		  	obj.put("dataout", "ERROR");//输出参数
		  	log.sysLogMap(obj, request);
		}
		Component.print(idreturn, response);
	} 
	/**
	 * 根据证件类型和号码查询个人基础信息
	 * @author bjh
	 * @param request
	 * @param response
	 *@throws Exception
	 */
	@RequestMapping(params = "method=getaac147")
	public void getAAC147(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String aac058 = Component.getQuest("aac058", request);
	    String aac002 = Component.getQuest("aac002", request);
	    HashMap user = ss.getAAC147(aac058,aac002);
	    Component.print(Util.Encode(user), response);
	} 
	/**
	 * 获取下拉列表数据
	 * @author bjh
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params = "method=getselect")
	public void getSelect(HttpServletRequest request, HttpServletResponse response) throws Exception {
	    List data = ss.getSelect(Component.getQuest("lx", request));
	    Component.print(Util.Encode(data), response);
	}
	/**
	 * 获取证件类型下拉列表数据
	 * @author fcl
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params = "method=getselectaac058")
	public void getSelectaac058(HttpServletRequest request, HttpServletResponse response) throws Exception {
	    List data = ss.getSelectaac058(Component.getQuest("lx", request));
	    Component.print(Util.Encode(data), response);
	}
	/**
	 * 校验身份证
	 * @author bjh
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params = "method=checksfz")
	public void checksfz(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String aac002 = Component.getQuest("id", request);
		HashMap map = new HashMap();
		map.put("aac002", aac002);
		String res = ss.checksfz(map);	   	  
	    Component.print(res, response);
	}
	/**
	 * 批量导入个人信息登记
	 * @author fcl
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params = "method=saveunitpl")
	public void saveunitpl(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String idreturn = "";
		String json = request.getParameter("data");
		ArrayList rows = (ArrayList)Util.Decode(json);		
		HashMap row = (HashMap)rows.get(0);		
		Map m = new HashMap();
	 	String sss = sys.callFunction("ZJ_GET_EVENTID", m);
	 	String[] s = sss.split("&");
	 	String aaz002 = s[0];     	    	
	 	row.put("aaz002", aaz002);	
	 	row.put("baz805","JS0000000003");
		idreturn = ss.insertUnitpl(row);
		HashMap obj = new HashMap();
		obj.put("domainid", "ZYK");  //分系统号，见sys_log_bm
		obj.put("log_type", "T02");   //日志类别，见sys_log_bm
		obj.put("userid", Component.getSession("userid", request)); 	//操作人
		obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
		obj.put("content", "人员基础信息批量导入业务日记id为："+aaz002);
		obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
		obj.put("czrlb", "L01");     //操作人类别，见sys_log_bm
		obj.put("datain", ""); 		//输入参数
		obj.put("dataout", "Ok");	//输出参数
		log.sysLogMap(obj, request);
	    Component.print(idreturn, response);
	} 
	/**
	 * 批量导入个人信息校验
	 * @author fcl
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params = "method=saveunitpl1")
	public void saveunitpl1(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String idreturn = "";
		String eventid = request.getParameter("data");	
		HashMap row = new HashMap();
		row.put("eventid", eventid);
		Map m = new HashMap();
	 	String sss = sys.callFunction("ZJ_GET_EVENTID", m);
	 	String[] s = sss.split("&");
	 	String aaz002 = s[0];     	    	
	 	row.put("aaz002", aaz002);	
	 	row.put("baz805","JS0000000003");
		idreturn = ss.insertUnitpl1(row);
		HashMap obj = new HashMap();
		obj.put("domainid", "ZYK");  //分系统号，见sys_log_bm
		obj.put("log_type", "T02");   //日志类别，见sys_log_bm
		obj.put("userid", Component.getSession("userid", request)); 	//操作人
		obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
		obj.put("content", "人员基础信息批量导入业务日记id为："+aaz002);
		obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
		obj.put("czrlb", "L01");     //操作人类别，见sys_log_bm
		obj.put("datain", ""); 		//输入参数
		obj.put("dataout", "Ok");	//输出参数
		log.sysLogMap(obj, request);
	    Component.print(idreturn, response);
	} 
	/**
	* 批量导入错误信息
	* @author duy
	* @param request
	* @param response
	*@throws Exception
	*/ 
	@RequestMapping(params = "method=gettemp")
	public void gettemp(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = Component.getQuest("id", request);	
		if(id.contains(">")){
			String[]  str = id.split(">");
			String str1 = str[1].substring(0,str[1].lastIndexOf("<"));
			id=str1;
		}
	    HashMap parms = sys.getGridSort(request);
	    String json = Util.Encode(ss.gettemp(new Object[] {id},parms));
	    Component.print(json, response);
	}
}